<template>
  <view class="me-view">
    <!-- 个人信息界面 -->
    <!-- 工具栏 -->
    <uni-drawer ref="showLeft" mode="left" :width="250" @change="change($event,'showLeft')">
      <view class="tool-view">
        <view class="tool-box">
          <view class="tool-item" @click="addUser">
            <image class="tool-img" src="../../static/img/add-user.png"></image>
            <text>添加好友</text>
          </view>
          <view class="tool-item" @click="publish">
            <image class="tool-img" src="../../static/img/pub.png"></image>
            <text>发布笔记</text>
          </view>
          <view class="tool-item" @click="publishTripNew">
            <image class="tool-img" src="../../static/img/trip-new.png"></image>
            <text>发布资讯</text>
          </view>
          <view class="tool-item" @click="myCmt">
            <image class="tool-img" src="../../static/img/cmt.png"></image>
            <text>我的评论</text>
          </view>
          <view class="tool-item" @click="myBrowseHistory">
            <image class="tool-img" src="../../static/img/log.png"></image>
            <text>浏览记录</text>
          </view>
        </view>
      </view>  
    </uni-drawer>
    <view class="info-view" :style="backgroundStyle">
      <!-- 用户登录后显示的信息 -->
      <view class="info-view-bg" v-if="data.curUser!=null">
        <view class="status_bar">
          <!-- 这里是状态栏 -->
        </view>
        <view class="menu-box">
          <image @click="showMenu" class="menu-img" src="../../static/img/menu.png"></image>
        </view>
        
          <view class="info-box">
              <image class="avatar" :src="data.curUser.avatar"></image>
              <view class="na-box">
                <text class="name">{{data.curUser.userName}}</text>
                <text class="account">账号：{{data.curUser.account}}</text>
              </view>
            </view>
            
            <view class="des-box">
              <text class="des-text">{{data.curUser.infoDes}}</text>
            </view>
              <!-- 关注数、点赞数 -->
              <!-- 设置和编辑信息 -->
              <view class="info-bottom-box">
                <view class="afl-box">
                  <view class="afl-item" @click="showMyAttention">
                    <text class="aflt-num">{{data.curUser.attNum}}</text>
                    <text class="afl-text">关注</text>
                  </view>
                  <view class="afl-item">
                    <text class="aflt-num">{{data.curUser.funNum}}</text>
                    <text class="afl-text">粉丝</text>
                  </view>
                  <view class="afl-item">
                    <text class="aflt-num">{{data.curUser.likeStarNum}}</text>
                    <text class="afl-text">点赞与收藏</text>
                  </view>
                </view>
                <view class="info-icon-box">
                  <view class="info-icon-item">
                    <image @click="editInfo" class="info-icon" src="../../static/img/edit.png"></image>
                  </view> 
                  <view class="info-icon-item">
                      <image @click="setting" class="info-icon" src="../../static/img/setting1.png"></image>
                  </view>    
                </view>
              </view>
      </view>
      
      <!-- 未登录显示的信息 -->
      <view class="login-btn" @click="login" v-if="data.curUser == null">
        登录
      </view>
            
        </view>
        <!-- 个人笔记、收藏、赞过 -->
        <!-- 导航栏 -->
        <view class="nsl-box">
          <view class="nsl-item" @tap="swiperChange(0)" :class="data.nslIndex == 0 ? 'nav-actived' : ''">
            <text class="nsl-text">笔记</text>
          </view>
          <view class="nsl-item" @tap="swiperChange(1)" :class="data.nslIndex == 1 ? 'nav-actived' : ''">
            <text class="nsl-text">资讯</text>
          </view>
          <view class="nsl-item" @tap="swiperChange(2)" :class="data.nslIndex == 2 ? 'nav-actived' : ''">
            <text class="nsl-text">收藏</text>
          </view>
          <view class="nsl-item" @tap="swiperChange(3)" :class="data.nslIndex == 3 ? 'nav-actived' : ''">
            <text class="nsl-text">赞过</text>
          </view>
        </view>
        <!-- 显示内容 -->
          <swiper class="nsl-swiper" :current="data.nslIndex" @change="swiperChange($event.detail.current)">
            <!-- 笔记 -->
            <swiper-item class="nsl-swiper-item">
              <scroll-view class="note-list" scroll-y="true" lower-threshold="50" @scrolltolower="getMoreNote">
                <view class="tip-tag" v-if="data.myNoteList == null ||data.myNoteList.length == 0">
                  暂无内容/(ㄒoㄒ)/~~
                </view>
                <view class="waterfall">
                  <!-- 笔记 -->
                  <view class="flowList">
                    <view class="note" v-for="idx in data.myNoteLeft" @click="showNote(data.myNoteList[idx].id,idx)">
                      <!-- 笔记封面 -->
                      <view class="note-img-box">
                        <image mode="widthFix" lazy-load="true" class="note-img" :src="data.myNoteList[idx].url"></image>
                      </view>
                      <!-- 笔记标题内容 -->
                      <view class="note-content-box">
                        <rich-text class="note-text">{{data.myNoteList[idx].title}}</rich-text>
                      </view>
                      <!-- 笔记作者信息和点赞情况 -->
                      <view class="note-info">
                        <view class="note-author-info">
                          <image class="author-avatar" lazy-load="true" :src="data.myNoteList[idx].authorAvatar"></image>
                          <text class="author-name">{{data.myNoteList[idx].authorName}}</text>
                        </view>
                        <view class="like-box" @click.stop="likeMyNote(idx)">
                          <image class="like-icon" v-show="data.myNoteList[idx].like == 0" src="../../static/img/like-btn1.png"></image>
                          <image class="like-icon" v-show="data.myNoteList[idx].like > 0" src="../../static/img/like-btn2.png"></image>
                          <text class="like-num">{{data.myNoteList[idx].likeNum}}</text>
                        </view>
                      </view>
                    </view>
                  </view>
                  <view class="flowList">
                   <view class="note" v-for="idx in data.myNoteRight" @click="showNote(data.myNoteList[idx].id,idx)">
                     <!-- 笔记封面 -->
                     <view class="note-img-box">
                       <image mode="widthFix" lazy-load="true" class="note-img" :src="data.myNoteList[idx].url"></image>
                     </view>
                     <!-- 笔记标题内容 -->
                     <view class="note-content-box">
                       <rich-text class="note-text">{{data.myNoteList[idx].title}}</rich-text>
                     </view>
                     <!-- 笔记作者信息和点赞情况 -->
                     <view class="note-info">
                       <view class="note-author-info">
                         <image class="author-avatar" lazy-load="true" :src="data.myNoteList[idx].authorAvatar"></image>
                         <text class="author-name">{{data.myNoteList[idx].authorName}}</text>
                       </view>
                       <view class="like-box" @click.stop="likeMyNote(idx)">
                         <image class="like-icon" v-show="data.myNoteList[idx].like == 0" src="../../static/img/like-btn1.png"></image>
                         <image class="like-icon" v-show="data.myNoteList[idx].like > 0" src="../../static/img/like-btn2.png"></image>
                         <text class="like-num">{{data.myNoteList[idx].likeNum}}</text>
                       </view>
                     </view>
                   </view>         
                </view>   
                </view>
                <view class="tip-tag" v-if="data.myNoteList.length != 0 && data.myNoteList.length >= data.totalNote">
                  暂无更多了
                </view>
              </scroll-view>
            </swiper-item>
            <!-- 资讯 -->
            <swiper-item class="nsl-swiper-item">
              <scroll-view scroll-y="true" class="note-list" lower-threshold="50" @scrolltolower="getMoreTripNew">
                <view class="trip-item" @click="showTripNew(item.id,index)" v-for="(item,index) in data.myTripNewList" :key="index">
                  <image mode="aspectFill" lazy-load="true" class="trip-img" :src="item.cover"></image>
                  <view class="trip-des">
                    <text class="trip-title">{{item.title}}</text>
                    <text class="trip-road">{{item.departure}}->{{item.destination}}</text>
                    <text class="trip-road">{{item.startTime}}->{{item.dayNum}}天</text>
                    <view class="trip-info">
                      <view class="author-info">
                        <image class="trip-avatar" lazy-load="true" :src="item.authorAvatar"></image>
                        <text class="trip-name">{{item.authorName}}</text>
                      </view>
                      <view class="trip-like-box" @click.stop="likeMyTripNew(index)">
                        <image class="trip-like" v-if="item.like == 0 || item.like == null" src="../../static/img/like-btn1.png"></image>
                        <image class="trip-like" v-else src="../../static/img/like-btn2.png"></image>
                        <text class="trip-like-num">{{item.likeNum}}</text>
                      </view>
                      
                    </view>
                  </view>
                </view>
                <view class="tip-tag" v-if="data.myTripNewList.length != 0 && data.myTripNewList.length >= data.totalMyTripNew">
                  暂无更多了
                </view>
              </scroll-view>
            </swiper-item>
            <!-- 收藏 -->
            <swiper-item class="nsl-swiper-item">
              <view class="nsl-in-box">
                <view class="nsl-in-item" @tap="starSwiperChange(0)" :class="data.starIndex == 0 ? 'nav-in-actived' : ''">
                  <text>笔记</text>
                </view>
                <view class="nsl-in-item" @tap="starSwiperChange(1)" :class="data.starIndex == 1 ? 'nav-in-actived' : ''">
                  <text>资讯</text>
                </view>
              </view>
              <swiper class="nsl-in-swiper" :current="data.starIndex" @change="starSwiperChange($event.detail.current)">
                <swiper-item>
                  <scroll-view class="note-in-list" scroll-y="true" lower-threshold="50" @scrolltolower="getMoreStar">
                    <view class="tip-tag" v-if="data.starList == null || data.starList.length == 0">
                      暂无内容/(ㄒoㄒ)/~~
                    </view>
                    <view class="waterfall">
                      <!-- 笔记 -->
                      <view class="flowList">
                        <view class="note" v-for="idx in data.starLeft" @click="showNote(data.starList[idx].id,idx)">
                          <!-- 笔记封面 -->
                          <view class="note-img-box">
                            <image mode="widthFix" lazy-load="true" class="note-img" :src="data.starList[idx].url"></image>
                          </view>
                          <!-- 笔记标题内容 -->
                          <view class="note-content-box">
                            <rich-text class="note-text">{{data.starList[idx].title}}</rich-text>
                          </view>
                          <!-- 笔记作者信息和点赞情况 -->
                          <view class="note-info">
                            <view class="note-author-info">
                              <image class="author-avatar" lazy-load="true" :src="data.starList[idx].authorAvatar"></image>
                              <text class="author-name">{{data.starList[idx].authorName}}</text>
                            </view>
                            <view class="like-box" @click.stop="likeStarNote(idx)">
                              <image class="like-icon" v-if="data.starList[idx].like > 0" src="../../static/img/like-btn2.png"></image>
                              <image class="like-icon" v-else src="../../static/img/like-btn1.png"></image>
                              <text class="like-num">{{data.starList[idx].likeNum}}</text>
                            </view>
                          </view>
                        </view>
                      </view>
                      <view class="flowList">
                       <view class="note" v-for="idx in data.starRight" @click="showNote(data.starList[idx].id)">
                         <!-- 笔记封面 -->
                         <view class="note-img-box">
                           <image mode="widthFix" lazy-load="true" class="note-img" :src="data.starList[idx].url"></image>
                         </view>
                         <!-- 笔记标题内容 -->
                         <view class="note-content-box">
                           <rich-text class="note-text">{{data.starList[idx].title}}</rich-text>
                         </view>
                         <!-- 笔记作者信息和点赞情况 -->
                         <view class="note-info">
                           <view class="note-author-info">
                             <image class="author-avatar" lazy-load="true" :src="data.starList[idx].authorAvatar"></image>
                             <text class="author-name">{{data.starList[idx].authorName}}</text>
                           </view>
                           <view class="like-box" @click.stop="likeStarNote(idx)">
                             <image class="like-icon" v-if="data.starList[idx].like > 0" src="../../static/img/like-btn2.png"></image>
                             <image class="like-icon" v-else src="../../static/img/like-btn1.png"></image>
                             <text class="like-num">{{data.starList[idx].likeNum}}</text>
                           </view>
                         </view>
                       </view>         
                    </view>   
                    </view>
                    <view class="tip-tag" v-if="data.starList.length != 0 && data.starList.length >= data.totalStar">
                      暂无更多了
                    </view>
                  </scroll-view>
                </swiper-item>
                <swiper-item>
                  <scroll-view scroll-y="true" class="trip-new" lower-threshold="50" @scrolltolower="getMoreStarTripNew">
                    <view class="trip-item" @click="showTripNew(item.id,index)" v-for="(item,index) in data.starTripNewList" :key="index">
                      <image mode="aspectFill" lazy-load="true" class="trip-img" :src="item.cover"></image>
                      <view class="trip-des">
                        <text class="trip-title">{{item.title}}</text>
                        <text class="trip-road">{{item.departure}}->{{item.destination}}</text>
                        <text class="trip-road">{{item.startTime}}->{{item.dayNum}}天</text>
                        <view class="trip-info">
                          <view class="author-info">
                            <image class="trip-avatar" lazy-load="true" :src="item.authorAvatar"></image>
                            <text class="trip-name">{{item.authorName}}</text>
                          </view>
                          <view class="trip-like-box" @click.stop="likeStarTripNew(index)">
                            <image class="trip-like" v-if="item.like == 0 || item.like == null" src="../../static/img/like-btn1.png"></image>
                            <image class="trip-like" v-else src="../../static/img/like-btn2.png"></image>
                            <text class="trip-like-num">{{item.likeNum}}</text>
                          </view>
                          
                        </view>
                      </view>
                    </view>
                    <view class="tip-tag" v-if="data.starTripNewList.length != 0 && data.starTripNewList.length >= data.totalStarTripNew">
                      暂无更多了
                    </view>
                  </scroll-view>

                </swiper-item>
              </swiper>
              
            </swiper-item>
            <!-- 点赞 -->
            <swiper-item class="nsl-swiper-item">
              <view class="nsl-in-box">
                <view class="nsl-in-item" @tap="likeSwiperChange(0)" :class="data.likeIndex == 0 ? 'nav-in-actived' : ''">
                  <text>笔记</text>
                </view>
                <view class="nsl-in-item" @tap="likeSwiperChange(1)" :class="data.likeIndex == 1 ? 'nav-in-actived' : ''">
                  <text>资讯</text>
                </view>
              </view>
              <swiper class="nsl-in-swiper" :current="data.likeIndex" @change="likeSwiperChange($event.detail.current)">
                <swiper-item>
              <scroll-view class="note-in-list" scroll-y="true" lower-threshold="50" @scrolltolower="getMoreLike">
                <view class="tip-tag" v-if="data.likeList == null || data.likeList.length == 0">
                  暂无内容/(ㄒoㄒ)/~~
                </view>
                <view class="waterfall">
                  <!-- 笔记 -->
                  <view class="flowList">
                    <view class="note" v-for="idx in data.likeLeft" @click="showNote(data.likeList[idx].id,idx)">
                      <!-- 笔记封面 -->
                      <view class="note-img-box">
                        <image mode="widthFix" lazy-load="true" class="note-img" :src="data.likeList[idx].url"></image>
                      </view>
                      <!-- 笔记标题内容 -->
                      <view class="note-content-box">
                        <rich-text class="note-text">{{data.likeList[idx].title}}</rich-text>
                      </view>
                      <!-- 笔记作者信息和点赞情况 -->
                      <view class="note-info">
                        <view class="note-author-info">
                          <image class="author-avatar" lazy-load="true" :src="data.likeList[idx].authorAvatar"></image>
                          <text class="author-name">{{data.likeList[idx].authorName}}</text>
                        </view>
                        <view class="like-box" @click.stop="likeLikeNote(idx)">
                          <image class="like-icon" v-if="data.likeList[idx].like > 0" src="../../static/img/like-btn2.png"></image>
                          <image class="like-icon" v-else src="../../static/img/like-btn1.png"></image>
                          <text class="like-num">{{data.likeList[idx].likeNum}}</text>
                        </view>
                      </view>
                    </view>
                  </view>
                  <view class="flowList">
                   <view class="note" v-for="idx in data.likeRight" @click="showNote(data.likeList[idx].id,idx)">
                     <!-- 笔记封面 -->
                     <view class="note-img-box">
                       <image mode="widthFix" lazy-load="true" class="note-img" :src="data.likeList[idx].url"></image>
                     </view>
                     <!-- 笔记标题内容 -->
                     <view class="note-content-box">
                       <rich-text class="note-text">{{data.likeList[idx].title}}</rich-text>
                     </view>
                     <!-- 笔记作者信息和点赞情况 -->
                     <view class="note-info">
                       <view class="note-author-info">
                         <image class="author-avatar" lazy-load="true" :src="data.likeList[idx].authorAvatar"></image>
                         <text class="author-name">{{data.likeList[idx].authorName}}</text>
                       </view>
                       <view class="like-box" @click.stop="likeLikeNote(idx)">
                         <image class="like-icon" v-if="data.likeList[idx].like > 0" src="../../static/img/like-btn2.png"></image>
                         <image class="like-icon" v-else src="../../static/img/like-btn1.png"></image>
                         <text class="like-num">{{data.likeList[idx].likeNum}}</text>
                       </view>
                     </view>
                   </view>         
                </view>   
                </view>
                <view class="tip-tag" v-if="data.likeList.length != 0 && data.likeList.length >= data.totalLike">
                  暂无更多了
                </view>
              </scroll-view>
                </swiper-item>
                <swiper-item>
                  <scroll-view scroll-y="true" class="trip-new" lower-threshold="50" @scrolltolower="getMoreLikeTripNew">
                    <view class="trip-item" @click="showTripNew(item.id,index)" v-for="(item,index) in data.likeTripNewList" :key="index">
                      <image mode="aspectFill" lazy-load="true" class="trip-img" :src="item.cover"></image>
                      <view class="trip-des">
                        <text class="trip-title">{{item.title}}</text>
                        <text class="trip-road">{{item.departure}}->{{item.destination}}</text>
                        <text class="trip-road">{{item.startTime}}->{{item.dayNum}}天</text>
                        <view class="trip-info">
                          <view class="author-info">
                            <image class="trip-avatar" lazy-load="true" :src="item.authorAvatar"></image>
                            <text class="trip-name">{{item.authorName}}</text>
                          </view>
                          <view class="trip-like-box" @click.stop="likeLikeTripNew(index)">
                            <image class="trip-like" v-if="item.like == 0 || item.like == null" src="../../static/img/like-btn1.png"></image>
                            <image class="trip-like" v-else src="../../static/img/like-btn2.png"></image>
                            <text class="trip-like-num">{{item.likeNum}}</text>
                          </view>
                          
                        </view>
                      </view>
                    </view>
                    <view class="tip-tag" v-if="data.likeTripNewList.length != 0 && data.likeTripNewList.length >= data.totalLikeTripNew">
                      暂无更多了
                    </view>
                  </scroll-view>
                </swiper-item>
              </swiper>
              
            </swiper-item>
          </swiper>
  </view>
</template>

<script setup>
import { reactive, ref,toRefs,computed } from 'vue';
import { onShow,onLoad,onUnload,onHide } from '@dcloudio/uni-app'
import helper from '../../common/helper.js'

const data = reactive({
  // 用户信息
  curUser: uni.getStorageSync("curUser") || null,
  nslIndex: 0,
  starIndex:0,
  likeIndex:0,
  showMenu: 1,
  myNoteList:[],
  myNotePageNum:0,
  myNotePageSize:10,
  totalNote: 0,
  likeList:[],
  likePageNum:0,
  likePageSize: 10,
  starList:[],
  starPageNum: 0,
  starPageSize: 10,
  totalStar: 0,
  myNoteLeft:[],
  myNoteRight:[],
  myNoteLeftHeight:0,
  myNoteRightHeight:0,
  totalLike: 0,
  likeLeft:[],
  likeRight:[],
  likeLeftHeight:0,
  likeRightHeight:0,
  starLeft:[],
  starRight:[],
  starLeftHeight:0,
  starRightHeight:0,
  myTripNewList:[],
  totalMyTripNew: 0,
  myTripNewPageNum: 0,
  myTripNewPageSize: 10,
  likeTripNewList:[],
  totalLikeTripNew: 0,
  likeTripNewPageNum: 0,
  likeTripNewPageSize: 10,
  starTripNewList:[],
  totalStarTripNew: 0,
  starTripNewPageNum: 0,
  starTripNewPageSize: 10,
});

function login(){
  console.log("跳转到登录...")
  uni.navigateTo({
    url:"/subpages/userLogin/userLogin"
  })
}
// 每次进入页面执行
onShow(() => {
  console.log('onShow')
  data.curUser= uni.getStorageSync("curUser") || null
  initData()
  if(data.curUser != null){
    getMyNote()
    getStarNote()
    getLikeNote()
    getMyTripNew()
    getLikeTripNew()
    getStarTripNew()
  }
  //监听页面返回的点赞事件
  updateLikeData()
})

onUnload((options)=>{
  uni.$off('like');  
})

function updateLikeData(){
  uni.$on('like',(likeData)=>{
    if(likeData.event != 1){
      return
    }
    if(likeData.delete == 1){
      initData()
      return
    }
    //我的笔记或资讯
    if(data.nslIndex < 2){
      if(data.nslIndex == 0){
        console.log("点赞事件:我的笔记"+likeData.index+" "+likeData.like)
        if(data.myNoteList[likeData.index].like < likeData.like){
          data.myNoteList[likeData.index].likeNum++
        }else if(data.myNoteList[likeData.index].like > likeData.like){
          data.myNoteList[likeData.index].likeNum--
        }
        data.myNoteList[likeData.index].like = likeData.like 
      }else{
        console.log("点赞事件:我的资讯"+likeData.index+" "+likeData.like)
        if(data.myTripNewList[likeData.index].like < likeData.like){
          data.myTripNewList[likeData.index].likeNum++
        }else if(data.myTripNewList[likeData.index].like > likeData.like){
          data.myTripNewList[likeData.index].likeNum--
        }
        data.myTripNewList[likeData.index].like = likeData.like
      }
    }else{
      if(data.nslIndex == 2){
        //收藏页面
        console.log("点赞事件:我的收藏"+likeData.index+" "+likeData.like)
        if(data.starIndex == 0){
          if(data.starList[likeData.index].like < likeData.like){
            data.starList[likeData.index].likeNum++
          }else if(data.starList[likeData.index].like > likeData.like){
            data.starList[likeData.index].likeNum--
          }
          data.starList[likeData.index].like = likeData.like
        }else{
          if(data.starTripNewList[likeData.index].like < likeData.like){
            data.starTripNewList[likeData.index].likeNum++
          }else if(data.starTripNewList[likeData.index].like > likeData.like){
            data.starTripNewList[likeData.index].likeNum--
          }
          data.starTripNewList[likeData.index].like = likeData.like
        }
      }else{
        //点赞页面
        console.log("点赞事件:我的点赞"+likeData.index+" "+likeData.like)
        if(data.likeIndex == 0){
          if(data.likeList[likeData.index].like < likeData.like){
            data.likeList[likeData.index].likeNum++
          }else if(data.likeList[likeData.index].like > likeData.like){
            data.likeList[likeData.index].likeNum--
          }
          data.likeList[likeData.index].like = likeData.like
        }else{
          if(data.likeTripNewList[likeData.index].like < likeData.like){
            data.likeTripNewList[likeData.index].likeNum++
          }else if(data.likeTripNewList[likeData.index].like > likeData.like){
            data.likeTripNewList[likeData.index].likeNum--
          }
          data.likeTripNewList[likeData.index].like = likeData.like
        }
      }
    }
  })
}

function initData(){
  data.myNoteList=[]
  data.myNotePageNum=0
  data.myNotePageSize=10
  data.totalNote= 0
  data.likeList=[]
  data.likePageNum=0
  data.likePageSize= 10
  data.starList=[]
  data.starPageNum= 0
  data.starPageSize= 10
  data.totalStar= 0
  data.myNoteLeft=[]
  data.myNoteRight=[]
  data.myNoteLeftHeight=0
  data.myNoteRightHeight=0
  data.totalLike= 0
  data.likeLeft=[]
  data.likeRight=[]
  data.likeLeftHeight=0
  data.likeRightHeight=0
  data.starLeft=[]
  data.starRight=[]
  data.starLeftHeight=0
  data.starRightHeight=0
  data.myTripNewList=[]
  data.totalMyTripNew= 0
  data.myTripNewPageNum= 0
  data.myTripNewPageSize= 10
  data.likeTripNewList=[]
  data.totalLikeTripNew= 0
  data.likeTripNewPageNum= 0
  data.likeTripNewPageSize= 10
  data.starTripNewList=[]
  data.totalStarTripNew= 0
  data.starTripNewPageNum= 0
  data.starTripNewPageSize= 10
}

let backgroundStyle = computed(() => {
  if(data.curUser != null && data.curUser.infoBg != null){
    return{
      backgroundImage: `url(${data.curUser.infoBg})`,
      backgroundSize: 'cover', 
      backgroundPosition: 'center', 
      backgroundRepeat: 'no-repeat', 
    };
  }
});

async function likeMyNote(idx){
  let noteId = data.myNoteList[idx].id
  if(data.myNoteList[idx].like > 0){
    let res = await helper.dislikeNoteReq(noteId)
    if(res.data.code == 200){
      data.myNoteList[idx].like = 0
      data.myNoteList[idx].likeNum--
    }
  }else{
    let res = await helper.likeNoteReq(noteId)
    if(res.data.code == 200){
      data.myNoteList[idx].like = 1
      data.myNoteList[idx].likeNum++
    }
  }
}

async function likeStarNote(idx){
  let noteId = data.starList[idx].id
  if(data.starList[idx].like > 0){
    let res = helper.dislikeNoteReq(noteId)
    if(res.data.code == 200){
      data.starList[idx].like = 0
      data.starList[idx].likeNum--
    }
  }else{
    let res = await helper.likeNoteReq(noteId)
    if(res.data.code == 200){
      data.starList[idx].like = 1
      data.starList[idx].likeNum++
    }
  }
}

async function likeLikeNote(idx){
  let noteId = data.likeList[idx].id
  if(data.likeList[idx].like > 0){
    let res = helper.dislikeNoteReq(noteId)
    if(res.data.code == 200){
      data.likeList[idx].like = 0
      data.likeList[idx].likeNum--
    }
  }else{
    let res = await helper.likeNoteReq(noteId)
    if(res.data.code == 200){
      data.likeList[idx].like = 1
      data.likeList[idx].likeNum++
    }
  }
}


async function likeMyTripNew(index){
  let tripNewId = data.myTripNewList[index].id
  if(data.myTripNewList[index].like > 0){
    let res = await helper.dislikeTripNewReq(tripNewId)
    if(res.data.code == 200){
      data.myTripNewList[index].like = 0
      data.myTripNewList[index].likeNum--
    }
  }else{
    let res = await helper.likeTripNewReq(tripNewId)
    if(res.data.code == 200){
      data.myTripNewList[index].like = 1
      data.myTripNewList[index].likeNum++
    }
  }
}

async function likeLikeTripNew(index){
  let tripNewId = data.likeTripNewList[index].id
  console.log(data.likeTripNewList)
  if(data.likeTripNewList[index].like > 0){
    let res = await helper.dislikeTripNewReq(tripNewId)
    if(res.data.code == 200){
      data.likeTripNewList[index].like = 0
      data.likeTripNewList[index].likeNum--
    }
  }else{
    let res = await helper.likeTripNewReq(tripNewId)
    if(res.data.code == 200){
      data.likeTripNewList[index].like = 1
      data.likeTripNewList[index].likeNum++
    }
  }
}

async function likeStarTripNew(index){
  let tripNewId = data.starTripNewList[index].id
  if(data.starTripNewList[index].like > 0){
    let res = await helper.dislikeTripNewReq(tripNewId)
    if(res.data.code == 200){
      data.starTripNewList[index].like = 0
      data.starTripNewList[index].likeNum--
    }
  }else{
    let res = await helper.likeTripNewReq(tripNewId)
    if(res.data.code == 200){
      data.starTripNewList[index].like = 1
      data.starTripNewList[index].likeNum++
    }
  }
}

function getMyNote(){
  uni.request({
      url: helper.webUrl+'/note/getMyNote', 
      method:'GET',
      header:{
        'token': helper.getToken()
      },
      data: {
        pageNum:data.myNotePageNum,
        pageSize:data.myNotePageSize,
      },
      success: (res) => {
        console.log(res.data);
        //处理笔记数据
        if(res.data.code == 200){
          let list = res.data.data.record
          data.totalNote = res.data.data.total
          data.myNotePageNum++
          for(let i = 0; i < list.length; i++){
            data.myNoteList.push(list[i])
            if(data.myNoteLeftHeight <= data.myNoteRightHeight){
              let num = list[i].height / list[i].width > helper.maxNoteImg ? helper.maxNoteImg : list[i].height / list[i].width
              data.myNoteLeftHeight += num + helper.noteBox
              data.myNoteLeft.push(data.myNoteList.length-1)
            }else{
              let num = list[i].height / list[i].width > helper.maxNoteImg ? helper.maxNoteImg : list[i].height / list[i].width
              data.myNoteRightHeight += num + helper.noteBox
              data.myNoteRight.push(data.myNoteList.length-1)
            }
          }
        }
      },
      fail: (err) => {
        console.error('请求失败:', err);
      }
  });
}

function getMoreNote(){
  console.log("加载更多笔记。。。")
  //判断是否加载完
  if(data.totalNote <= data.myNoteList.length){
    return
  }
  getMyNote()
}

function getMyTripNew(){
  uni.request({
      url: helper.webUrl+'/tripNew/getMyTripNew', 
      method:'GET',
      header:{
        'token': helper.getToken()
      },
      data: {
        pageNum:data.myTripNewPageNum,
        pageSize:data.myTripNewPageSize,
      },
      success: (res) => {
        console.log(res.data);
        //处理笔记数据
        if(res.data.code == 200){
          let list = res.data.data.record
          data.totalStarTripNew = res.data.data.total
          data.myTripNewPageNum++
          for(let i = 0; i < list.length; i++){
            list[i].startTime = helper.getDate(list[i].startTime)
            data.myTripNewList.push(list[i])
          }
        }
      },
      fail: (err) => {
        console.error('请求失败:', err);
      }
  });
}

function getMoreTripNew(){
  console.log("加载更多点赞的笔记。。。")
  if(data.totalMyTripNew <= data.likeList.length){
    return
  }
  getMyTripNew()
}

function getStarTripNew(){
  uni.request({
      url: helper.webUrl+'/tripNew/getStarTripNew', 
      method:'GET',
      header:{
        'token': helper.getToken()
      },
      data: {
        pageNum:data.starTripNewPageNum,
        pageSize:data.starTripNewPageSize,
      },
      success: (res) => {
        console.log(res.data);
        //处理笔记数据
        if(res.data.code == 200){
          let list = res.data.data.record
          data.totalStarTripNew = res.data.data.total
          data.starTripNewPageNum++
          for(let i = 0; i < list.length; i++){
            list[i].startTime = helper.getDate(list[i].startTime)
            data.starTripNewList.push(list[i])
          }
        }
      },
      fail: (err) => {
        console.error('请求失败:', err);
      }
  });
}

function getMoreStarTripNew(){
  console.log("加载更多点赞的笔记。。。")
  if(data.totalStarTripNew <= data.likeList.length){
    return
  }
  getStarTripNew()
}

function getLikeTripNew(){
  uni.request({
      url: helper.webUrl+'/tripNew/getLikeTripNew', 
      method:'GET',
      header:{
        'token': helper.getToken()
      },
      data: {
        pageNum:data.likeTripNewPageNum,
        pageSize:data.likeTripNewPageSize,
      },
      success: (res) => {
        console.log(res.data);
        //处理笔记数据
        if(res.data.code == 200){
          let list = res.data.data.record
          data.totalLikeTripNew = res.data.data.total
          data.likeTripNewPageNum++
          for(let i = 0; i < list.length; i++){
            list[i].startTime = helper.getDate(list[i].startTime)
            data.likeTripNewList.push(list[i])
          }
        }
      },
      fail: (err) => {
        console.error('请求失败:', err);
      }
  });
}

function getMoreLikeTripNew(){
  console.log("加载更多点赞的笔记。。。")
  if(data.totalLikeTripNew <= data.likeList.length){
    return
  }
  getLikeTripNew()
}

function getStarNote(){
  uni.request({
      url: helper.webUrl+'/note/getStarNote', 
      method:'GET',
      header:{
        'token': helper.getToken()
      },
      data: {
        pageNum:data.starPageNum,
        pageSize:data.starPageSize,
      },
      success: (res) => {
        console.log(res.data);
        //处理笔记数据
        if(res.data.code == 200){
          let list = res.data.data.record
          data.totalStar = res.data.data.total
          data.starPageNum++
          for(let i = 0; i < list.length; i++){
            data.starList.push(list[i])
            if(data.starLeftHeight <= data.starRightHeight){
              let num = list[i].height / list[i].width > helper.maxNoteImg ? helper.maxNoteImg : list[i].height / list[i].width
              data.starLeftHeight += num + helper.noteBox
              data.starLeft.push(data.starList.length - 1)
            }else{
              let num = list[i].height / list[i].width > helper.maxNoteImg ? helper.maxNoteImg : list[i].height / list[i].width
              data.starRightHeight += num + helper.noteBox
              data.starRight.push(data.starList.length - 1)
            }
          }
        }
      },
      fail: (err) => {
        console.error('请求失败:', err);
      }
  });
}

function getMoreStar(){
  console.log("加载更多收藏的笔记。。。")
  if(data.totalStar <= data.starList.length){
    return
  }
  getStarNote()
}

function getLikeNote(){
  uni.request({
      url: helper.webUrl+'/note/getLikeNote', 
      method:'GET',
      header:{
        'token': helper.getToken()
      },
      data: {
        pageNum:data.likePageNum,
        pageSize:data.likePageSize,
      },
      success: (res) => {
        console.log(res.data);
        //处理笔记数据
        if(res.data.code == 200){
          let list = res.data.data.record
          data.totalLike = res.data.data.total
          data.likePageNum++
          for(let i = 0; i < list.length; i++){
            data.likeList.push(list[i])
            if(data.likeLeftHeight <= data.likeRightHeight){
              let num = list[i].height / list[i].width > helper.maxNoteImg ? helper.maxNoteImg : list[i].height / list[i].width
              data.likeLeftHeight += num + helper.noteBox
              data.likeLeft.push(data.likeList.length - 1)
            }else{
              let num = list[i].height / list[i].width > helper.maxNoteImg ? helper.maxNoteImg : list[i].height / list[i].width
              data.likeRightHeight += num + helper.noteBox
              data.likeRight.push(data.likeList.length - 1)
            }
          }
        }
      },
      fail: (err) => {
        console.error('请求失败:', err);
      }
  });
}

function getMoreLike(){
  console.log("加载更多点赞的笔记。。。")
  if(data.totalLike <= data.likeList.length){
    return
  }
  getLikeNote()
}

const showLeft = ref(null)

const showMenu = () =>{
  showLeft.value.open()
}
// 关闭窗口
const closeMenu = () => {
  showLeft.value.close()
}
// 抽屉状态发生变化触发
function change(e, type) {
  console.log((type === 'showLeft' ? '左窗口' : '右窗口') + (e ? '打开' : '关闭'));
  showLeft[type] = e
}

function swiperChange(index){
    data.nslIndex = index
}

function starSwiperChange(index){
    data.starIndex = index
}

function likeSwiperChange(index){
    data.likeIndex = index
}

function showNote(noteId,index){
  console.log("查看笔记"+noteId)
  uni.navigateTo({
    url:`/subpages/noteDetail/noteDetail?noteId=${noteId}&index=${index}&event=1`
  })
}

function showTripNew(tripNewId,index){
  console.log("查看资讯"+tripNewId)
  uni.navigateTo({
    url:`/subpages/tripNew/tripNew?tripNewId=${tripNewId}&index=${index}&event=1`
  })
}

function addUser(){
  console.log("添加好友。。。")
  uni.navigateTo({
    url:"/subpages/addUser/addUser"
  })
}

function publish(){
  console.log("发布笔记。。。")
  uni.navigateTo({
    url:"/subpages/publish/publish"
  })
}

function publishTripNew(){
  console.log("发布资讯。。。")
  uni.navigateTo({
    url:"/subpages/publishTripNew/publishTripNew"
  })
}

function showMyAttention(){
  uni.navigateTo({
    url:"/subpages/myAttention/myAttention"
  })
}

function myCmt(){
  console.log("我的评论。。。")
  uni.navigateTo({
    url:"/subpages/myCmt/myCmt"
  })
}

function myBrowseHistory(){
  console.log("我的浏览记录....")
  uni.navigateTo({
    url:"/subpages/browseHistory/browseHistory"
  })
}

function editInfo(){
  console.log("编辑资料")
  uni.navigateTo({
    url:"/subpages/editInfo/editInfo"
  })
}

function setting(){
  console.log("设置")
  uni.navigateTo({
    url:"/subpages/setting/setting"
  })
}

</script>

<style>
.me-view{
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
.login-btn{
  width: 100px;
  height: 100px;
  background-color: #949494;
  margin: auto;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 50%;
  font-size: 22px;
  color: #fff;
}
.menu-box{
  height: 5vh;
  padding-top: 20px;
  padding-left: 5px;
}
.menu-img{
  width: 30px;
  height: 30px;
}
.info-icon-item{
  padding: 8px;
  background-color: rgba(255, 255, 255, 0.2);
  border-radius: 30%;
  margin-right: 5px;
  border: 1px solid #fff;
}
.info-icon{
  width: 35px;
  height: 35px;
  margin-left: 2px;
}
.nsl-in-swiper{
  height: 80vh;
}
.nsl-in-box{
  display: flex;
  height: 5vh;
  border-bottom: 1px solid #c5c5c5;
}
.nsl-in-item{
  width: 20%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 16px;
  font-weight: bold;
  color: #949494;
}
.nav-in-actived{
  color: #000;
}
.tool-view{
  width: 100%;
  height: 100%;
  background-color: #f4f4f4;
  padding-top: 100px;
}
.tool-box{
  width: 80%;
  background-color: #fff;
  margin-inline: auto;
  border-radius: 15px;
}
.tool-item{
  width: 100%;
  font-size: 20px;
  padding: 15px;
  text-align: center;
  display: flex;
  justify-content: center;
  align-items: center;
}
.tool-img{
  width: 30px;
  height: 30px;
  padding-right: 5px;
}
</style>
